package com.jason.quectel0805.daos;

import com.jason.quectel0805.entities.User;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

/**
 * @author：Jason
 * @date：2022/8/10 11:35
 * @email：1129847330@qq.com
 * @description: 专门用来操作User表
 *
 * DAO:database access operator
 */
@Dao
public interface UserDao {
    /**
     * 增
     *
     * @param user,不定参数，意思是当前参数的数目是不固定的
     */
    @Insert
    void insertUser(User... user);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertUser(List<User> user);

    /**
     * 查询
     *
     * @param sex
     * @return
     */
    @Query("select * from user where sex=:sex")
    List<User> selectUser(String sex);

    @Query("select * from user")
    List<User> selectAllUser();

    /**
     * 修改
     *
     * @param targetAge
     * @param name
     */
    @Query("update user set age=:targetAge where name=:name")
    void updateUser(int targetAge, String name);

    /**
     * 删除
     */
    @Query("delete from user where sex=:sex")
    void deleteUser(String sex);
}